#coding:utf-8
"""

"""
import time,traceback,datetime,requests,random,socket,json,re,execjs
from pymysql import Connection, cursors, err

class card_spider(object):
    def __init__(self):
        self.url = 'https://vipapi.qimingpian.com/DataList/productListVip'
        self.headers = {
            'Accept': 'application/json, text/plain, */*',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
        }

    def main_parser(self):
        form_data = {
            'time_interval': '',
            'tag': '',
            'tag_type': '',
            'province': '',
            'lunci': '',
            'page': 1,
            'num': 20,
            'unionid': ''
        }
        response = requests.post(url=self.url,headers=self.headers,data=form_data)
        response = response.text
        self.detail_response(response)

    def detail_response(self,response):
        response = json.loads(response)
        encrypt_data = response['encrypt_data']
        print('获取的加密数据 --> {}'.format(encrypt_data))
        print('解析加密参数..........')
        js_content = execjs.compile(open(r'企名片.js','r',encoding='utf-8').read())
        js_content = js_content.call('o',encrypt_data)
        print('解析完成 结果是:')
        print(js_content)
        print('================')
        results = js_content['list']
        all_num = js_content['count']
        print('网页总量 --> {} 条'.format(all_num))
        for result in results:
            print(result)


if __name__ == '__main__':

    client = card_spider()
    client.main_parser()